define([
    "config",
    "commonLet",
    "angularModule",
    "jquery",
    "angular"
], function(config, commonLet) {
	// new
	let pageCss = function() {
		console.log("pageCss：页面样式初始化");
	};

	Object.assign(pageCss.prototype, {
        // baseLet
        // config
        config: "",
        // baseUrl: config.path.SERVICEURL,
        baseUrl: commonLet.BASEURL,
        // time
        time: commonLet.TIME,
        // 引用angular内部方法，抛出去给API使用
        angularScope: function () {
            // console.log("pageCss***angularScope***function")
        },
        // 初始化
        init: function(event) {
            if (!event) return;

            // 加缀时间戳
            this.time = commonLet.TIME;
            let ngApp = "bimApiAgular" + this.time;
            let ngController = "bimApiCtrl" + this.time;

            // 整体外壳
            let BIMViewAPIcontent = $("<div class='BIMView-API-content'></div>");
            BIMViewAPIcontent.attr({"onselectstart": "return false", "ng-app": ngApp, "ng-controller": ngController});
            $("#" + event).append(BIMViewAPIcontent);
            $("#" + event).append("<link rel='stylesheet' type='text/css' href='" +
                this.baseUrl +
                "/Module/css/bimView-api-3.css?" +
                this.time + "' />");

            BIMViewAPIcontent.append("<div bimview-api-slider></div>");
            BIMViewAPIcontent.append("<div bimview-api-bottom></div>");
            BIMViewAPIcontent.append("<div bimview-api-drag></div>");
            BIMViewAPIcontent.append("<div bimview-api-canvas3d></div>");
            $(".BIMView-API-content").css("display", "none");

            // 手动启动angular
            angular.bootstrap(document.querySelector(".BIMView-API-content"), [ngApp]);

            // 一些小组件的方法事件（不方便用css表示或者不适合其他）
            // 下拉组件dropdown系列相关
            $(".BIMView-API-content .BIMView-API-drag .dropdown .dropbtn").on("click", function() {
                //$(".BIMView-API-content .BIMView-API-drag .dropdown .dropdown-content").css("display", "block");
                $(this).parent(".dropdown").find(".dropdown-content").css("display", "block");
            });
            $(".BIMView-API-content .BIMView-API-drag .dropdown, .BIMView-API-content .BIMView-API-drag .dropdown .dropdown-content").on("mouseleave", function() {
                //$(".BIMView-API-content .BIMView-API-drag .dropdown .dropdown-content").css("display", "none");
                $(this).find(".dropdown-content").css("display", "none");
                $(this).parent(".dropdown").find(".dropdown-content").css("display", "none");
            });
            $(".BIMView-API-content .BIMView-API-drag .dropdown .dropdown-content a").on("click", function() {
                //$(".BIMView-API-content .BIMView-API-drag .dropdown .dropdown-content").css("display", "none");
                $(this).parent(".dropdown-content").css("display", "none");
            });

            // 通过controller来获取Angular应用
            let appElement = document.querySelector("[ng-controller="+ngController+"]");
            // 获取$scope变量
            let $scope = angular.element(appElement).scope();
            // 调用angular中变量/方法
            // console.log($scope.demo);
            // $scope.modelDemo();
            // 如果改变了angular中的值，想同步到Angular控制器中，则需要调用$apply()方法即可
            // $scope.$apply();

            // 给抛出去的方法赋值
            Object.assign(this.angularScope.prototype,{
                initCanvas: function (id, callback) {
                    // $scope.modelDemo();
                    // console.log("pageCss***angularScope***demo***抛出去的方法")
                    setTimeout(function () {
                        $(".BIMView-API-content").css("display", "block");
                        callback(id);
                    });
                }
            });

        }
    });

	return pageCss;
});